<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../css/style.css">
    <script src="../plugins/echarts/echarts.min.js"></script>
    <!--element日期所需-->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <link rel="stylesheet" href="../plugins/elementui/index.css">
</head>
<body class="hold-transition">
<!--日期控件-->
<div id="date">
    <template>
        <div class="block">
            <br><span>请选择日期区间</span>
            <el-date-picker
                    v-model="value"
                    type="daterange"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :default-time="['00:00:00', '23:59:59']"
                    @blur="findData()">
            </el-date-picker>
        </div>
    </template>
</div>


<div id="app">
    <div class="content-header">
        <h1>统计分析<small>体检收入占比</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>体检收入占比</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
            <div id="chart1" style="height:600px;"></div>
        </div>
    </div>
</div>
</body>

<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
            el: "#date",
            data: {
                value: ''
            },
        created() {
            var date1 = new Date(),
                end = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();
            var date2 = new Date(date1);
            date2.setDate(date1.getDate() - 7);
            var begin = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
            this.sendAndGet(begin, end)
        },
            methods: {
                findData() {
                    var beginDate = this.value[0];
                    var begin = beginDate.getFullYear() + "-" + (beginDate.getMonth() + 1) + "-" + beginDate.getDate();
                    var endDate = this.value[1];
                    var end = endDate.getFullYear() + "-" + (endDate.getMonth() + 1) + "-" + endDate.getDate();
                    this.sendAndGet(begin, end)
                },
                sendAndGet(begin, end) {
                    var myChart = echarts.init(document.getElementById('chart1'));

                    axios.get("/report/getIncomeReport.do?begin=" + begin + "&end=" + end).then((res) => {
                        if (res.data.flag) {
                            myChart.setOption({
                                tooltip: {
                                    trigger: 'item',
                                    formatter: '{a} <br/>{b}: {c} ({d}%)'
                                },
                                toolbox: {
                                    feature: {
                                        saveAsImage: {}
                                    }
                                },
                                legend: {
                                    orient: 'vertical',
                                    left: 10,
                                    data: res.data.data.setMealList
                                },
                                series: [{
                                    name: '访问来源',
                                    type: 'pie',
                                    radius: ['50%', '70%'],
                                    avoidLabelOverlap: false,
                                    label: {
                                        show: false,
                                        position: 'center'
                                    },
                                    emphasis: {
                                        label: {
                                            show: true,
                                            fontSize: '30',
                                            fontWeight: 'bold'
                                        }
                                    },
                                    labelLine: {
                                        show: false
                                    },
                                    data: res.data.data.income
                                }]
                            });
                        } else {
                            this.$message.error("暂无数据")
                        }
                    });
                }
            }
        });


    </script>
</html>
